
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.util.AdminAreaCodeUtils;
import com.insigma.business.qrcode.common.util.BizCheckUtil;
import com.insigma.business.qrcode.soldier.dao.SoldierTpAllDao;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.dto.SoldierBasicInfoBSearcher;
import com.insigma.business.qrcode.soldier.dto.SoldierTpAllBSearcher;
import com.insigma.business.qrcode.soldier.dto.SoldierTpAllDetailBO;
import com.insigma.business.qrcode.soldier.entity.DataStatsCDO;
import com.insigma.business.qrcode.soldier.entity.SoldierBasicInfoDO;
import com.insigma.business.qrcode.soldier.entity.SoldierTpAllDO;
import com.insigma.business.qrcode.soldier.service.SoldierTpAllService;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("soldierTpAllService")
public class SoldierTpAllServiceImpl implements SoldierTpAllService {

    @Autowired(required = false)
    private SoldierTpAllDao soldierTpAllDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<SoldierTpAllDO> search(final SoldierTpAllBSearcher soldierTpAllBSearcher) {
        return soldierTpAllDao.search(soldierTpAllBSearcher);
    }
   
    @Override
    public SoldierTpAllDO get(final String id){
        return soldierTpAllDao.get(id);
    }

    
    @Override
    public Integer insert(final SoldierTpAllDO soldierTpAllDO){
        soldierTpAllDO.setId(sequenceGenerator.genKey(SequenceNameConstant.SOLDIER_TP_ALL_ID));
        return soldierTpAllDao.insert(soldierTpAllDO);
    }

    
    @Override
    public Integer update(final SoldierTpAllDO soldierTpAllDO){
        return soldierTpAllDao.update(soldierTpAllDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return soldierTpAllDao.delete(id,modifierType,modifierId);
    }

    @Override
    public SoldierTpAllDO getByIdCardNo(String idCardNo) {
        return soldierTpAllDao.getByIdCardNo(idCardNo);
    }

    @Override
    public List<SoldierTpAllDO> get3Ydate() {
        return soldierTpAllDao.get3Ydate();
    }

    @Override
    public void update3YTest(String idCardNo, String result) {

        soldierTpAllDao.update3YTest(idCardNo, result);
    }

    @Override
    public List<SoldierTpAllDO> listAllShare(String areaLike) {
        return  soldierTpAllDao.listAllShare(areaLike);

    }

    @Override
    public Integer countUnemploymentRegistration(String areaLike) {
        return soldierTpAllDao.countUnemploymentRegistration(areaLike);
    }

    @Override
    public List<DataStatsCDO> countUnemploymentRegistrationAreaMap(String adminAreaCode, String startCalDateTime) {
        int level = AdminAreaCodeUtils.getLevel(adminAreaCode);
        String areaLike = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%";
        int nextLevel = level + 1;
        int levelLength = AdminAreaCodeUtils.getLevelLength(nextLevel);

        return soldierTpAllDao.countUnemploymentRegistrationAreaMap(areaLike, nextLevel, levelLength, startCalDateTime);
    }

    @Override
    public List<SoldierTpAllDO> listAllJobTaxCompany(String areaLike) {
        return soldierTpAllDao.listAllJobTaxCompany(areaLike);
    }

    @Override
    public List<SoldierBasicInfoDO> searchAll() {
        return soldierTpAllDao.queryAllTest();
    }

    @Override
    public List<SoldierTpAllDO> listAllShareOfTax(String areaLike) {
        return soldierTpAllDao.listAllShareOfTax(areaLike);
    }

    @Override
    public List<SoldierTpAllDO> listAllShareOfAllCompany(String areaLike) {
        return soldierTpAllDao.listAllShareOfAllCompany(areaLike);
    }

    @Override
    public List<SoldierTpAllDO> get3YdateOfSocialMore(String year) {
        return soldierTpAllDao.get3YdateOfSocialMore(year);
    }

    @Override
    public List<SoldierTpAllDO> listAllUnemploymentRegistration(String areaLike) {
        return soldierTpAllDao.listAllUnemploymentRegistration(areaLike);
    }

    @Override
    public List<SoldierTpAllDO> searchUnemploymentRegistration(SoldierTpAllBSearcher innerSearcher) {
        return soldierTpAllDao.searchUnemploymentRegistration(innerSearcher);
    }

    @Override
    public int updateUnemploymentRegistrationTime(String idCardNo, String time) {
        BizCheckUtil.checkNotBlank(idCardNo, "idCardNo不空");
        return soldierTpAllDao.updateUnemploymentRegistrationTime(idCardNo, time);
    }

    @Override
    public List<DataStatsCDO> countYear3UnemploymentRegistrationAreaMap(String adminAreaCode, String startCalDateTime) {
        int level = AdminAreaCodeUtils.getLevel(adminAreaCode);
        String areaLike = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%";
        int nextLevel = level + 1;
        int levelLength = AdminAreaCodeUtils.getLevelLength(nextLevel);

        return soldierTpAllDao.countYear3UnemploymentRegistrationAreaMap(areaLike, nextLevel, levelLength, startCalDateTime);
    }

    @Override
    public int countYear3UnemploymentRegistration(String adminAreaCode, String currentYearStartTime) {
        return soldierTpAllDao.countYear3UnemploymentRegistration(adminAreaCode, currentYearStartTime);
    }

    @Override
    public List<DataStatsCDO> countUnemploymentRegistrationAgeMap(String adminAreaCode, String startCalDateTime) {
        return soldierTpAllDao.countYear3UnemploymentRegistrationAgeMap(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%", startCalDateTime);
    }

    @Override
    public List<SoldierTpAllDO> getAllNotRetired(String startYear, String endYear) {
        return soldierTpAllDao.getAllNotRetired(startYear, endYear);
    }

    @Override
    public Integer countShareholder(String startYear, String endYear) {
        return soldierTpAllDao.countShareholder(startYear, endYear);
    }

    @Override
    public SoldierTpAllDO isMilitaryEnterprise(String uniscid) {
        return soldierTpAllDao.isMilitaryEnterprise(uniscid);
    }

    @Override
    public List<SoldierTpAllDO> listNotRetiredSocialSecurity(String adminAreaCode, Boolean flag) {
        return soldierTpAllDao.listNotRetiredSocialSecurity(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%", flag);
    }

    @Override
    public List<SoldierTpAllDO> searchNotRetiredSocialSecurity(SoldierTpAllBSearcher searcher) {
        if (Strings.isNotBlank(searcher.getAdminAreaCode())) {
            searcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(searcher.getAdminAreaCode()));
        }
        return soldierTpAllDao.searchNotRetiredSocialSecurity(searcher);
    }

    @Override
    public List<String> listIdCardNoOfLowSide() {
        return soldierTpAllDao.listIdCardNoOfLowSide();
    }

    @Override
    public List<String> listIdCardNoOfSubsistenceAllowance() {
        return soldierTpAllDao.listIdCardNoOfSubsistenceAllowance();
    }

    @Override
    public List<String> listIdCardNoOfExtremelyPoor() {
        return soldierTpAllDao.listIdCardNoOfExtremelyPoor();
    }

    @Override
    public List<SoldierTpAllDO> listAllSocialSecurity(SoldierBasicInfoBSearcher searcher) {
        return soldierTpAllDao.searchAllSocialSecurity(searcher);
    }

    @Override
    public Integer updateLatestSocialTime(String idCardNo, String time) {
        return soldierTpAllDao.updateLatestSocialTime(idCardNo, time);
    }

    @Override
    public List<SoldierTpAllDO> searchItem(SoldierBasicInfoBSearcher searcher) {
        if (Strings.isNotBlank(searcher.getEmploymentFlag())) {
            Date date = org.apache.commons.lang3.time.DateUtils.addMonths(new Date(), -3);
            String startCalDateTime = DateUtil.formatDate(date, "yyyy-MM");
            searcher.setStartCalDateTime(startCalDateTime);
        }

        if (Strings.isNotBlank(searcher.getAdminAreaCode())) {
            searcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(searcher.getAdminAreaCode()));
        }
        return soldierTpAllDao.searchItem(searcher);
    }

    @Override
    public Integer countNoSocialSecurityNum(String adminAreaCode) {
        return soldierTpAllDao.countNoSocialSecurityNum(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%");
    }

    @Override
    public Integer countEmploymentNum(String adminAreaCode, String startCalDateTime) {
        return soldierTpAllDao.countEmploymentNum(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%", startCalDateTime);
    }

    @Override
    public Integer countWithdrawNum(String adminAreaCode, String startCalDateTime) {
        return soldierTpAllDao.countWithdrawNum(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%", startCalDateTime);
    }

    @Override
    public List<DataStatsCDO> listDifficultyAgeRange(String areaLike) {
        return soldierTpAllDao.listDifficultyAgeRange(areaLike);
    }

    @Override
    public Integer countDifficulty(String adminAreaCode) {
        return soldierTpAllDao.countDifficulty(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) + "%");
    }

    @Override
    public List<DataStatsCDO> queryDifficultyAreaCount(String areaLike, int nextLevel, int levelLength) {

        return soldierTpAllDao.queryDifficultyAreaCount(areaLike, nextLevel, levelLength);
    }

    @Override
    public List<SoldierTpAllDO> searchSocialSecurityInfo(SoldierTpAllBSearcher searcher) {
        if (Strings.isNotBlank(searcher.getAdminAreaCode())) {
            searcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(searcher.getAdminAreaCode()) + "%");
        }
        return soldierTpAllDao.searchSocialSecurityInfo(searcher);
    }

    @Override
    public List<SoldierTpAllDetailBO> searchShareholder(SoldierTpAllBSearcher searcher) {
        if (Strings.isNotBlank(searcher.getAdminAreaCode())) {
            searcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(searcher.getAdminAreaCode()));
        }
        return soldierTpAllDao.searchShareholder(searcher);
    }

    @Override
    public List<SoldierTpAllDO> listSocialSecurityByIdCardNoList(List<String> idCardNoList) {
        return  soldierTpAllDao.listSocialSecurityByIdCardNoList(idCardNoList);
    }

    @Override
    public Integer countLowSide(String adminAreaCode) {
        Integer i = soldierTpAllDao.countLowSide(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode));
        if (i == null) {
            i = 0;
        }
        return i;
    }

    @Override
    public Integer countSubsistenceAllowance(String adminAreaCode) {
        Integer i = soldierTpAllDao.countSubsistenceAllowance(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode));
        if (i == null) {
            i = 0;
        }
        return i;
    }

    @Override
    public Integer countExtremelyPoor(String adminAreaCode) {
        Integer i = soldierTpAllDao.countExtremelyPoor(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode));
        if (i == null) {
            i = 0;
        }
        return i;
    }

    @Override
    public List<SoldierTpAllDO> listAllIdCardNoInTestTable() {
        return soldierTpAllDao.listAllIdCardNoInTestTable();
    }

    @Override
    public Integer countCommunityCorrection(String adminAreaCode) {
        Integer i = soldierTpAllDao.countCommunityCorrection(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode));
        if (i == null) {
            i = 0;
        }
        return i;
    }

    @Override
    public List<String> searchIdCardNo(SoldierTpAllBSearcher searcher) {
        if (Strings.isNotBlank(searcher.getAdminAreaCode())) {
            searcher.setAdminAreaCode(AdminAreaCodeUtils.getCutdAreaCode(searcher.getAdminAreaCode()));
        }
        return soldierTpAllDao.searchIdCardNo(searcher);
    }


}
